﻿package src {
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author AT
	 */
	public class CDPlayer extends MovieClip {
		static private var SPEED_LIMIT:int = 37;
		private var playSpeed_:int = 0;
		private var playStep_:int = 17;
		private var stopStep_:int = 7;
		
		public function CDPlayer():void {

		}
		
		public function playCD():void {
			this.removeEventListener(Event.ENTER_FRAME, decCDRotation);
			this.addEventListener(Event.ENTER_FRAME, incCDRotation);
		}
		
		public function stopCD():void {
			this.removeEventListener(Event.ENTER_FRAME, incCDRotation);
			this.addEventListener(Event.ENTER_FRAME, decCDRotation);
		}
		
		private function incCDRotation(event:Event):void {
			if (playSpeed_ < SPEED_LIMIT)
				playSpeed_ += (SPEED_LIMIT - playSpeed_) / playStep_;
			else 
				playSpeed_ = SPEED_LIMIT;
			this.rotation += playSpeed_;
		}
		
		private function decCDRotation(event:Event):void {
			if (playSpeed_ > 0)
				playSpeed_ -= playSpeed_ / stopStep_;
			else {
				playSpeed_ = 0
				this.removeEventListener(Event.ENTER_FRAME, decCDRotation);
			}
			this.rotation += playSpeed_;
		}
	}
	
}